<!DOCTYPE html>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <link rel="StyleSheet" type="text/css" href="/tpa/admin.css" />
      <link rel="StyleSheet" type="text/css" href="/tpa/jquery-ui.css" />
      <script type="text/javascript" src="/lib/js/jquery.js"></script>
      <script type="text/javascript" src="/lib/js/jquery.ui.js"></script>
      <script type="text/javascript" src="/lib/js/meccano.js"></script>
      <script type="text/javascript">
         function DeleteComment(id)
         {
            $("#dialog").dialog({
               bgiframe: true,
               resizable: false,
               height:140,
               modal: true,
               overlay: {
                  backgroundColor: '#000',
                  opacity: 0.5
               },
               buttons: {
                  '{%$TR->meccano->delete%}': function() {
                     $.ajax({
                        type: 'GET',
                        url: '/admin/comments.php',
                        data: 'a=3&id='+ id,
                        dataType: 'text',
                        success: function(json)
                        {
                           if(json == 1)
                           {
                              $('#comment_'+id).remove();
                              ColorizeTr('comments_list');
                           }
                        }
                     });
                     $(this).dialog('close');
                  },
                  '{%$TR->meccano->cancel%}': function() {
                     $(this).dialog('close');
                  }
               }
            });
            return false;
         }

         function toogleComment(id, el)
         {
            var state = $('>img', el).attr('rel');
            var action = state == 'on' ? 1 : 2;
            $.ajax({
               type: "GET",
               url: "/admin/comments.php",
               data: "a="+ action +"&id="+id,
               dataType: "text",
               success: function(json){
                  if(json == 1)
                  {
                     var img = $('>img', el);
                     if(state == 'off')
                     {
                        img.attr('rel','on');
                        img.attr('src','/tpa/img/off.png');
                     } else
                     {
                        img.attr('rel','off');
                        img.attr('src','/tpa/img/on.png');
                     }
                  }
               }
            });
         }
      </script>
   </head>
   <body>
      <div id="tabedContent">

         {%if $data%}
         {%foreach from=$data item='c' name='i'%}
         {%if $smarty.foreach.i.first%}
         <table class="grid" width="98%" cellpadding="0" cellspacing="0" id="comments_list">
            <tr>
               <th>{%$TR->meccano->info%}</th>
               <th>{%$TR->meccano->message%}</th>
               <th>{%$TR->meccano->article%}</th>
               <th>&nbsp;</th>
            </tr>
            {%/if%}

            <tr {%cycle values=",class='odd'"%} id="comment_{%$c.id%}">
               <td class="lt" width="20%">
                  {%if $c.uid%}{%$TR->meccano->user%}: <b>{%$c.user.login%}</b><br />
                  {%elseif $c.name%}{%$TR->meccano->name%}: <b>{%$c.name%}</b><br />{%/if%}
                  {%$TR->meccano->date%}: <b>{%$c.cdate|date_format:$lang.longdate%}</b><br />
                  IP: <b>{%$c.ip%}</b><br />
                  {%if $c.email%}e-mail: <b>{%$c.email%}</b><br />{%/if%}
                  {%if $c.city%}{%$TR->meccano->city%}: <b>{%$c.city%}</b><br />{%/if%}
                  {%if $c.country%}{%$TR->meccano->country%}: <b>{%$c.country%}</b>{%/if%}
                  {%if $c.site%}web: <b>{%$c.site%}</b>{%/if%}
               </td>
               <td class="lt">{%$c.comment%}</td>
               <td class="lt">
                  {%$c.article.title%}<br />
                  <i style="line-height: 20px;">{%$c.article.category.title%}</i>
               </td>
               <td class="ct" width="7%" style="padding-top: 15px;">
                  {%if $c.hidden eq 1%}
                  <a href="" onclick="toogleComment({%$c.id%}, this); return false;"><img src='/tpa/img/off.png' rel="on" /></a>
                  {%else%}
                  <a href="" onclick="toogleComment({%$c.id%}, this); return false;"><img src='/tpa/img/on.png' rel="off" /></a>
                  {%/if%}
                  &nbsp; <a href="" onclick="return DeleteComment({%$c.id%});"><img src="/tpa/img/16/delete.gif" width="16" height="16" /></a>
               </td>
            </tr>

            {%if $smarty.foreach.i.last%}
         </table>

         {%if $pages%}
         <div class="paginator">
            {%foreach from=$pages.links item='p'%}
            {%if $p.current%}<span class="warn">{%$p.num%}</span>
            {%else%}<a href="{%$p.href%}">{%$p.num%}</a>
            {%/if%}
            {%/foreach%}
         </div>
         {%/if%}

         {%/if%}
         {%/foreach%}
         {%else%}

         <div class="warn ct" style="padding-top:50px;">There aren't any comments</div>
         {%/if%}


      </div>

      <div id="dialog" title="{%$TR->meccano->delete%}?" style="display:none;">
         <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>{%$TR->meccano->confirm_delcomment%}</p>
      </div>

   </body>
</html>